package com.jrx.anytxn.investor.timer.job.noticeRouteResult.step;

import com.jrx.anytxn.investor.entity.TlFundRouteLog;
import com.jrx.anytxn.investor.handler.IInvestorLoanRouteHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 资金源路由通知 - processor
 *
 * @author liuyang
 * @date 2020-06-05
 */
@Service
public class InvestorNoticeRouteResultProcessor implements ItemProcessor<TlFundRouteLog, TlFundRouteLog> {

    Logger logger = LoggerFactory.getLogger(InvestorNoticeRouteResultProcessor.class);

    @Autowired
    private IInvestorLoanRouteHandler investorLoanRouteHandler;

    /**
     * 资金源路由通知处理
     *
     * @param fundRouteLog 放款资金源路由记录
     * @return TlFundRouteLog 放款资金源路由记录
     * @throws Exception
     * @author liuyang
     * @date 2020-06-05
     */
    @Override
    public TlFundRouteLog process(TlFundRouteLog fundRouteLog) throws Exception {

        TlFundRouteLog updateFundRouteLog = new TlFundRouteLog();
        updateFundRouteLog.setId(fundRouteLog.getId());
        updateFundRouteLog.setTenantId(fundRouteLog.getTenantId());
        updateFundRouteLog.setOrganizationId(fundRouteLog.getOrganizationId());
        updateFundRouteLog.setCustomerId(fundRouteLog.getCustomerId());

        // 路由结果通知API
        String routeStatus = investorLoanRouteHandler.noticeApiFundResult(fundRouteLog, fundRouteLog.getFundId());

        updateFundRouteLog.setRouteStatus(routeStatus);

        return updateFundRouteLog;
    }
}
